package learn.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;

/**
 * @author sunliang
 * @version 1.0
 * @date 2021/2/3 19:50
 */
public class MyBatisUtil
{
  private final static SqlSessionFactory sqlSessionFactory;
  static
  {
    String resource = "resources/mybatis-config.xml";
    Reader reader = null;
    try
    {
      reader = Resources.getResourceAsReader(resource);
    } catch (IOException e)
    {
      System.out.println(e.getMessage());
    }
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
  }
  public static SqlSessionFactory getSqlSessionFactory()
  {
    return sqlSessionFactory;
  }
}
